<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<th:block th:include="include :: header('个人所得税新增及修改')" />
	<th:block th:include="include :: businessCSS" />
</head>
<body class="no-skin">
<div class="main-container" id="main-container">
	<div class="main-content">
	<form class="layui-form head-form">
	    <div class="north">
            <th:block th:include="include :: business_btn" />
	        <th:block th:include="include :: business_tpl('top')" />
    	</div>
	    <div class="mid-content">
	        <table class="layui-hide" id="dhtable" lay-filter="ftable"></table>
	    </div>
	   	<th:block th:include="include :: pageFooter" /> 
        </form>
	</div>
</div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: businessJS" />
<th:block th:include="include :: businessTableBtn" />
<th:block th:include="include :: inlineJS" />
<script type="text/javascript">
var $,layer,form,table,laydate,element;//定义layui模块
$.each(gridColumns.gridBody,function(i,v){//统计合计列数组
	if(v.totalRow && !v.hide)totalList[v.field]=i;
})
eachFields();//明细表格中的字段遍历
layui.use(['laydate', 'table','form','layer','jquery','util','element'], function () {
 	$ = layui.$,layer = layui.layer,form = layui.form,table = layui.table,laydate = layui.laydate,util = layui.util,element=layui.element;
 	beforeInit();//表单初始化之前的动作集合
 	layui.element.render();
 	$.get("/hr/salaryincometax/listbynid?nid="+nid,function(data){
		$.each(data.data,function(k,v){
			dataStr.push(v);
		});
		initTable();//初始化表格
	});
	toolbarEvent();//通用表格头部工具栏事件监听
	toolEvent('ftable');//行event事件监听
	monitorSort();//监听排序——重载赋值渲染
	table.on('edit(ftable)', function(obj){//工资计算
		var selector = obj.tr.selector+' td[data-field="'+obj.field+'"] div';
        var oldtext = $(selector).text();// 单元格编辑之前的值
		var editField = obj.field,//编辑单元格fieId
			editRow = obj.data,//编辑单元格行数据
			dataindex = $(obj.tr.selector).attr('data-index'),//编辑单元格下标
			isReturn,editValue;
		if(decimalObj[obj.field] > -1){//判断是否数值字段
			editValue = checkEdit(obj, decimalObj);//判断输入是否为数值，否则还原数值
			if(!editValue){
				editValue = oldtext;
				listData[dataindex][editField] = oldtext;
				isReturn = 1;
			}
			if(!isReturn){//输入的是数值并且改单元格是数值格式字段
				if(editField == 'iid'){//行号
					listData[dataindex]['iid'] = Number(editValue).toFixed(decimalObj.iid);
				}
				$.each(totalList,function(i,v){//重新计算统计字段数值
					if(i==editField){//编辑单元格为合计列时更新错误（单元格值的改变在监听后）
						$('.laytable-cell-1-0-'+v).last().text(Number(Number($('.laytable-cell-1-0-'+v).last().text())-Number(oldtext)+Number(editValue)).toFixed(decimalObj[i]));
					}else{
						var totalSum=0;
						$.each($('.laytable-cell-1-0-'+v),function(j,k){
							if(j>0 && j<$('.laytable-cell-1-0-'+v).length-1)totalSum+=Number($(k).text());//第一个是标题，最后一个是统计行
							if(j==$('.laytable-cell-1-0-'+v).length-1)$(k).text(totalSum.toFixed(decimalObj[i]));
						})
					}
				})
			}
			setTableValue('dhtable', dataindex, editField, editValue);//通过dom给表格内控件渲染值
			listData[dataindex][editField] = editValue;
		}
	});
})
</script>
</body>
</html>